/**
 * 物理索引
 */
import PhysicalIndexType from '../enums/PhysicalIndexType.js';

export default class PhysicalIndex {

    name = '';
    type = PhysicalIndexType.NORMAL;
    /**
     * @type {[String]}
     */
    mappingIds = [];

    constructor(name) {
        this.name = name;
    }

    static of(object) {
        if (typeof object !== 'object') {
            return undefined;
        }
        let clazz = new PhysicalIndex(this.name);
        clazz.update(object);
        return clazz;
    }

    update(object) {
        if (typeof object === 'object') {
            if (object.name !== undefined) {
                this.name = object.name;
            }
            if (object.type !== undefined) {
                this.type = PhysicalIndexType.validate(object.type);
            }
            if (Array.isArray(object.mappingIds)) {
                this.mappingIds = [...object.mappingIds];
            }
        }
        return this;
    }

    clone() {
        return PhysicalIndex.of(this);
    }

}
